library(tidyverse)
library(tidytuesdayR)
library(ggprism)
library(rmarkdown)
library(bookdown)
library(epuRate)
library(knitr)
library(citr)
library(emojifont)
library(countrycode)Using the tidytuesdayR package this task is easy:
data <- tidytuesdayR::tt_load(2021, week = 5)
plastics <- data$plasticsplastics_country <- plastics %>%
mutate(country = case_when(
country == "ECUADOR" ~ "Ecuador",
country == "NIGERIA" ~ "Nigeria",
country == "United Kingdom of Great Britain & Northern Ireland" ~ "Ireland",
TRUE ~ country
)) %>%
group_by(country) %>%
summarise(
total = sum(grand_total)
) %>%
arrange(desc(total)) %>%
mutate(abbreviation = countrycode(country, "country.name", "cldr.name.en")) %>%
mutate(flags = countrycode(country, "country.name", "unicode.symbol")) %>%
filter(!country == "EMPTY") %>%
mutate(total = ifelse(is.na(total), 0, total))
# mutate(flags_2 = case_when(
# TRUE ~ emo::flag(abbreviation)
# )
# )
head(plastics_country)
plastics_country %>%
ggplot(aes(total, reorder(abbreviation, -total))) +
geom_col() +
geom_text(aes(label = total), size = 3, color = "white", hjust = -0.7) +
labs(
x = "Total plastic counts [n]",
y = ""
) +
eafithemer::theme_eafit_dark() +
theme(
legend.title = element_blank(),
axis.line.x = element_line(color = "#FFFFFF"),
axis.ticks = element_line(color = "#FFFFFF"),
panel.grid = element_blank()
) +
scale_x_continuous(guide = "prism_offset_minor", limits = c(0, 270000)) +
coord_cartesian(expand = FALSE) +
ggsave("plastics-total-01.png", width = 10, height = 12.5)A work by Camilo Garcia